//
//  ChainTest.m
//  Charles
//
//  Created by Leo on 2019/7/1.
//  Copyright © 2019 charles. All rights reserved.
//

#import "ChainTest.h"
#import "ChainObjects.h"

@implementation ChainTest

+ (void)testChainOfResponsibility {
    // 创建职责链上的对象
    Support *alice = [[NoSupport alloc]initWithName:@"Alice"];
    Support *bob = [[LimitSupport alloc]initWithName:@"Bob" limit:10];
    Support *charlie = [[SpecialSupport alloc]initWithName:@"Charlie" number:29];
    Support *diana = [[LimitSupport alloc]initWithName:@"Diana" limit:15];
    Support *elmo = [[OddSupport alloc]initWithName:@"Elmo"];
    Support *fred = [[LimitSupport alloc]initWithName:@"Fred" limit:20];
    
    // 设置职责链
    alice.next = bob;
    bob.next = charlie;
    charlie.next = diana;
    diana.next = elmo;
    elmo.next = fred;
    
    // 制造各种编号的问题
//    for (NSInteger i = 0; i < 30; i++) {
        Trouble *trouble = [[Trouble alloc] initWithNumber:20];
        [alice support:trouble];
//    }
}

@end
